package com.example.blog.controller;

import com.example.blog.pojo.request.UserLoginRequest;
import com.example.blog.pojo.request.UserRegisterRequest;
import com.example.blog.pojo.response.Result;
import com.example.blog.pojo.response.UserInfoResponse;
import com.example.blog.pojo.response.UserLoginResponse;
import com.example.blog.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;
    @PostMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginRequest loginRequest){
        log.info("用户登录,userName:{}",loginRequest.getUserName());
        return userService.check(loginRequest);
    }

    @GetMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId){
        log.info("获取用户信息,userId:{}",userId);
        return userService.getUserInfo(userId);
    }

    @GetMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId){
        log.info("获取博客的作者信息,blogId:"+blogId);
        return userService.getAuthorInfo(blogId);
    }


    @PostMapping("/register")
    public Result register(@Validated @RequestBody UserRegisterRequest registerRequest){
        log.info("用户注册,userName:{}",registerRequest.getUserName());
        return Result.ok(userService.add(registerRequest));
    }
}












































